summaryrefslogtreecommitdiff
path: root/mlir/test/Bytecode
AgeCommit message (Collapse)Author
2025-02-04[MLIR] print/parse resource handle key quoted and escaped (#119746)Soren Lassen
resource keys have the problem that you can’t parse them from mlir assembly if they have special or non-printable characters, but nothing prevents you from specifying such a key when you create e.g. a DenseResourceElementsAttr, and it works fine in other ways, including bytecode emission and parsing this PR solves the parsing by quoting and escaping keys with special or non-printable characters in mlir assembly, in the same way as symbols, e.g.: ``` module attributes { fst = dense_resource<resource_fst> : tensor<2xf16>, snd = dense_resource<"resource\09snd"> : tensor<2xf16> } {} {-# dialect_resources: { builtin: { resource_fst: "0x0200000001000200", "resource\09snd": "0x0200000008000900" } } #-} ``` by not quoting keys without special or non-printable characters, the change is effectively backwards compatible the change is tested by: 1. adding a test with a dense resource handle key with special characters to `dense-resource-elements-attr.mlir` 2. adding special and unprintable characters to some resource keys in the existing lit tests `pretty-resources-print.mlir` and `mlir/test/Bytecode/resources.mlir`
2024-07-03[mlir][bytecode] Fix external resource bytecode parsing (#97650)Jeff Niu
The key was being dropped for external resources because they aren't present in the dialect resource name mapper.
2023-11-13[mlir][bytecode] Add bytecode writer config API to skip serialization of ↵Matteo Franciolini
resources (#71991) When serializing to bytecode, users can select the option to elide resources from the bytecode file. This will instruct the bytecode writer to serialize only the key and resource kind, while skipping serialization of the data buffer. At parsing, the IR is built in memory with valid (but empty) resource handlers.
2023-10-31[mlir][bytecode] Implements back deployment capability for MLIR dialects ↵Matteo Franciolini
(#70724) When emitting bytecode, clients can specify a target dialect version to emit in `BytecodeWriterConfig`. This exposes a target dialect version to the DialectBytecodeWriter, which can be queried by name and used to back-deploy attributes, types, and properties.
2023-08-09Finish renaming getOperandSegmentSizeAttr() from `operand_segment_sizes` to ↵Mehdi Amini
`operandSegmentSizes` This renaming started with the native ODS support for properties, this is completing it. A mass automated textual rename seems safe for most codebases. Drop also the ods prefix to keep the accessors the same as they were before this change: properties.odsOperandSegmentSizes reverts back to: properties.operandSegementSizes The ODS prefix was creating divergence between all the places and make it harder to be consistent. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D157173
2023-08-02[MLIR][Bytecode] Add missing field initializer in constructor initializer listMehdi Amini
Leaving this field unitialized could led to crashes when it'll diverge from the IRNumbering phase. Differential Revision: https://reviews.llvm.org/D156965
2023-07-28Add support for versioning properties in MLIR bytecodeMatteo Franciolini
[mlir] Add support for custom readProperties/writeProperties methods. Currently, operations that opt-in to adopt properties will see auto-generated readProperties/writeProperties methods to emit and parse bytecode. If a dialects opts in to use `usePropertiesForAttributes`, those definitions will be generated for the current definition of the op without the possibility to handle attribute versioning. The patch adds the capability for an operation to define its own read/write methods for the encoding of properties so that versioned operations can handle upgrading properties encodings. In addition to this, the patch adds an example showing versioning on NamedProperties through the dialect version API exposed by the reader. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D155340
2023-07-28Expose callbacks for encoding of types/attributesMatteo Franciolini
[mlir] Expose a mechanism to provide a callback for encoding types and attributes in MLIR bytecode. Two callbacks are exposed, respectively, to the BytecodeWriterConfig and to the ParserConfig. At bytecode parsing/printing, clients have the ability to specify a callback to be used to optionally read/write the encoding. On failure, fallback path will execute the default parsers and printers for the dialect. Testing shows how to leverage this functionality to support back-deployment and backward-compatibility usecases when roundtripping to bytecode a client dialect with type/attributes dependencies on upstream. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D153383
2023-07-28Revert "Expose callbacks for encoding of types/attributes"Mehdi Amini
This reverts commit b299ec16661f653df66cdaf161cdc5441bc9803c. The authorship informations were incorrect.
2023-07-28Expose callbacks for encoding of types/attributesMehdi Amini
[mlir] Expose a mechanism to provide a callback for encoding types and attributes in MLIR bytecode. Two callbacks are exposed, respectively, to the BytecodeWriterConfig and to the ParserConfig. At bytecode parsing/printing, clients have the ability to specify a callback to be used to optionally read/write the encoding. On failure, fallback path will execute the default parsers and printers for the dialect. Testing shows how to leverage this functionality to support back-deployment and backward-compatibility usecases when roundtripping to bytecode a client dialect with type/attributes dependencies on upstream. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D153383
2023-07-25[mlir:bytecode] Support lazy loading dynamically isolated regionsRiver Riddle
We currently only support lazy loading for regions that statically implement the IsolatedFromAbove trait, but that limits the amount of operations that can be lazily loaded. This review lifts that restriction by computing which operations have isolated regions when numbering, allowing any operation to be lazily loaded as long as it doesn't use values defined above. Differential Revision: https://reviews.llvm.org/D156199
2023-07-25[mlir:bytecode] Fix bytecode lazy loading for ops with multiple regionsRiver Riddle
We currently encode each region as a separate section, but the reader expects all of the regions to be in the same section. This updates the writer to match the behavior that the reader expects. Differential Revision: https://reviews.llvm.org/D156198
2023-06-26[mlir][bytecode] Fix lazy loading of non-isolated regionsRiver Riddle
The bytecode reader currently assumes all regions can be lazy loaded, which breaks reading any non-isolated region. This patch fixes that by properly handling nested non-lazy regions, and only considers isolated regions as lazy. Differential Revision: https://reviews.llvm.org/D153795
2023-06-23Fix bytecode reader/writer on big-endian platformsUlrich Weigand
This makes the bytecode reader/writer work on big-endian platforms. The only problem was related to encoding of multi-byte integers, where both reader and writer code make implicit assumptions about endianness of the host platform. This fixes the current test failures on s390x, and in addition allows to remove the UNSUPPORTED markers from all other bytecode-related test cases - they now also all pass on s390x. Also adding a GFAIL_SKIP to the MultiModuleWithResource unit test, as this still fails due to an unrelated endian bug regarding decoding of external resources. Differential Revision: https://reviews.llvm.org/D153567 Reviewed By: mehdi_amini, jpienaar, rriddle
2023-05-31[mlir][bytecode] Error if requested bytecode version is unsupportedKevin Gleason
Currently desired bytecode version is clamped to the maximum. This allows requesting bytecode versions that do not exist. We have added callsite validation for this in StableHLO to ensure we don't pass an invalid version number, probably better if this is managed upstream. If a user wants to use the current version, then omitting `setDesiredBytecodeVersion` is the best way to do that (as opposed to providing a large number). Adding this check will also properly error on older version numbers as we increment the minimum supported version. Silently claming on minimum version would likely lead to unintentional forward incompatibilities. Separately, due to bytecode version being `int64_t` and using methods to read/write uints, we can generate payloads with invalid version numbers: ``` mlir-opt file.mlir --emit-bytecode --emit-bytecode-version=-1 | mlir-opt <stdin>:0:0: error: bytecode version 18446744073709551615 is newer than the current version 5 ``` This is fixed with version bounds checking as well. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D151838
2023-05-26[MLIR] Add native Bytecode support for propertiesMehdi Amini
This is adding a new interface (`BytecodeOpInterface`) to allow operations to opt-in skipping conversion to attribute and serializing properties to native bytecode. The scheme relies on a new section where properties are stored in sequence { size, serialize_properties }, ... The operations are storing the index of a properties, a table of offset is built when loading the properties section the first time. This is a re-commit of 837d1ce0dc which conflicted with another patch upgrading the bytecode and the collision wasn't properly resolved before. Differential Revision: https://reviews.llvm.org/D151065
2023-05-25Revert "[MLIR] Add native Bytecode support for properties"Mehdi Amini
This reverts commit ca5a12fd69d4acf70c08f797cbffd714dd548348 and follow-up fixes: df34c288c428eb4b867c8075def48b3d1727d60b 07dc906883af660780cf6d0cc1044f7e74dab83e ab80ad0095083fda062c23ac90df84c40b4332c8 837d1ce0dc8eec5b17255291b3462e6296cb369b The first commit was incomplete and broken, I'll prepare a new version later, in the meantime pull this work out of tree.
2023-05-25[MLIR] Add native Bytecode support for propertiesMehdi Amini
This is adding a new interface (`BytecodeOpInterface`) to allow operations to opt-in skipping conversion to attribute and serializing properties to native bytecode. The scheme relies on a new section where properties are stored in sequence { size, serialize_properties }, ... The operations are storing the index of a properties, a table of offset is built when loading the properties section the first time. Back-deployment to version prior to 4 are relying on getAttrDictionnary() which we intend to deprecate and remove: that is putting a de-factor end-of-support horizon for supporting deployments to version older than 4. Differential Revision: https://reviews.llvm.org/D151065
2023-05-25[mlir][bytecode] Avoid recording null arglocs & realloc opnames.Jacques Pienaar
For block arg locs a common case is no/uknown location (where the producer signifies they don't care about blockarg location). Also avoid needing to dynamically resize opnames during parsing. Assumed to be post lazy loading change, so chose version 3. Differential Revision: https://reviews.llvm.org/D151038
2023-05-25Fix MLIR bytecode reader for unregistered dialectsMehdi Amini
At the moment we accept (in tests) unregistered dialects and in particular: "new_processor_id_and_range"() where there is no `.` separator. We probably will remove support for this from the parser, but for now we're adding compatibility support in the reader. Differential Revision: https://reviews.llvm.org/D151386
2023-05-24Fix MLIR bytecode reading of i0 IntegerAttrMehdi Amini
The move of the bytecode serialization to be tablegen driven in https://reviews.llvm.org/D144820 added a new condition in the reading path that forbid 0-sized integer, even though we still produce them. Fix #62920 Differential Revision: https://reviews.llvm.org/D151372
2023-05-21Preserve use-list orders in mlir bytecodeMatteo Franciolini
This patch implements a mechanism to read/write use-list orders from/to the mlir bytecode format. When producing bytecode, use-list orders are appended to each value of the IR. When reading bytecode, use-lists orders are loaded in memory and used at the end of parsing to sort the existing use-list chains. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D149755
2023-05-20Add support for Lazyloading to the MLIR bytecodeMehdi Amini
IsolatedRegions are emitted in sections in order for the reader to be able to skip over them. A new class is exposed to manage the state and allow the readers to load these IsolatedRegions on-demand. Differential Revision: https://reviews.llvm.org/D149515
2023-05-11[mlir][bytecode] Fix dialect version parsing.Jacques Pienaar
We were querying the wrong EncReader along some paths that resulted in failures depending on if one encountered an Attribute from an unloaded dialect before encountering an operation from that dialect. Also fix error where we were able to emit "custom" form for an attribute without custom form in TestDialect. Differential Revision: https://reviews.llvm.org/D150260
2023-05-08[mlir][bytecode] Fix typo in DenseElementsAttr.Jacques Pienaar
Was incorrectly marked as DenseIntElementsAttr (only used for SparseElementsAttr).
2023-05-01Introduce MLIR Op PropertiesMehdi Amini
This new features enabled to dedicate custom storage inline within operations. This storage can be used as an alternative to attributes to store data that is specific to an operation. Attribute can also be stored inside the properties storage if desired, but any kind of data can be present as well. This offers a way to store and mutate data without uniquing in the Context like Attribute. See the OpPropertiesTest.cpp for an example where a struct with a std::vector<> is attached to an operation and mutated in-place: struct TestProperties { int a = -1; float b = -1.; std::vector<int64_t> array = {-33}; }; More complex scheme (including reference-counting) are also possible. The only constraint to enable storing a C++ object as "properties" on an operation is to implement three functions: - convert from the candidate object to an Attribute - convert from the Attribute to the candidate object - hash the object Optional the parsing and printing can also be customized with 2 extra functions. A new options is introduced to ODS to allow dialects to specify: let usePropertiesForAttributes = 1; When set to true, the inherent attributes for all the ops in this dialect will be using properties instead of being stored alongside discardable attributes. The TestDialect showcases this feature. Another change is that we introduce new APIs on the Operation class to access separately the inherent attributes from the discardable ones. We envision deprecating and removing the `getAttr()`, `getAttrsDictionary()`, and other similar method which don't make the distinction explicit, leading to an entirely separate namespace for discardable attributes. Recommit d572cd1b067f after fixing python bindings build. Differential Revision: https://reviews.llvm.org/D141742
2023-05-01Revert "Introduce MLIR Op Properties"Mehdi Amini
This reverts commit d572cd1b067f1177a981a4711bf2e501eaa8117b. Some bots are broken and investigation is needed before relanding.
2023-05-01Introduce MLIR Op PropertiesMehdi Amini
This new features enabled to dedicate custom storage inline within operations. This storage can be used as an alternative to attributes to store data that is specific to an operation. Attribute can also be stored inside the properties storage if desired, but any kind of data can be present as well. This offers a way to store and mutate data without uniquing in the Context like Attribute. See the OpPropertiesTest.cpp for an example where a struct with a std::vector<> is attached to an operation and mutated in-place: struct TestProperties { int a = -1; float b = -1.; std::vector<int64_t> array = {-33}; }; More complex scheme (including reference-counting) are also possible. The only constraint to enable storing a C++ object as "properties" on an operation is to implement three functions: - convert from the candidate object to an Attribute - convert from the Attribute to the candidate object - hash the object Optional the parsing and printing can also be customized with 2 extra functions. A new options is introduced to ODS to allow dialects to specify: let usePropertiesForAttributes = 1; When set to true, the inherent attributes for all the ops in this dialect will be using properties instead of being stored alongside discardable attributes. The TestDialect showcases this feature. Another change is that we introduce new APIs on the Operation class to access separately the inherent attributes from the discardable ones. We envision deprecating and removing the `getAttr()`, `getAttrsDictionary()`, and other similar method which don't make the distinction explicit, leading to an entirely separate namespace for discardable attributes. Differential Revision: https://reviews.llvm.org/D141742
2023-04-29[mlir][bytecode] Allow client to specify a desired version.Jacques Pienaar
Add method to set a desired bytecode file format to generate. Change write method to be able to return status including the minimum bytecode version needed by reader. This enables generating an older version of the bytecode (not dialect ops, attributes or types). But this does not guarantee that an older version can always be generated, e.g., if a dialect uses a new encoding only available at later bytecode version. This clamps setting to at most current version. Differential Revision: https://reviews.llvm.org/D146555
2023-03-10Implements MLIR Bytecode versioning capabilityMatteo Franciolini
A dialect can opt-in to handle versioning through the `BytecodeDialectInterface`. Few hooks are exposed to the dialect to allow managing a version encoded into the bytecode file. The version is loaded lazily and allows to retrieve the version information while parsing the input IR, and gives an opportunity to each dialect for which a version is present to perform IR upgrades post-parsing through the `upgradeFromVersion` method. Custom Attribute and Type encodings can also be upgraded according to the dialect version using readAttribute and readType methods. There is no restriction on what kind of information a dialect is allowed to encode to model its versioning. Currently, versioning is supported only for bytecode formats. Reviewed By: rriddle, mehdi_amini Differential Revision: https://reviews.llvm.org/D143647
2022-12-09[MLIR/S90x] Convert tests to check 'target=...'Paul Robinson
Part of the project to eliminate special handling for triples in lit expressions.
2022-09-13[mlir:Bytecode] Add support for encoding resourcesRiver Riddle
Resources are encoded in two separate sections similarly to attributes/types, one for the actual data and one for the data offsets. Unlike other sections, the resource sections are optional given that in many cases they won't be present. For testing, bytecode serialization is added for DenseResourceElementsAttr. Differential Revision: https://reviews.llvm.org/D132729
2022-08-23[mlir:Bytecode] Use UNSUPPORTED instead of XFAIL for s390xRiver Riddle
Some tests still pass even though we don't claim big-endian support. Using UNSUPPORTED is a better indicator than XFAIL that we don't guarantee that the tests work.
2022-08-22[mlir] Fix bots after bytecode support was added in D131747River Riddle
* Fix ambiguous Twine constructor call * Ensure shift is 64-bit (for MSVC) * Disable bytecode tests on s390x (we don't support big endian right now)
2022-08-22[mlir] Add initial support for a binary serialization formatRiver Riddle
This commit adds a new bytecode serialization format for MLIR. The actual serialization of MLIR to binary is relatively straightforward, given the very very general structure of MLIR. The underlying basis for this format is a variable-length encoding for integers, which gets heavily used for nearly all aspects of the encoding (given that most of the encoding is just indexing into lists). The format currently does not provide support for custom attribute/type serialization, and thus always uses an assembly format fallback. It also doesn't provide support for resources. These will be added in followups, the intention for this patch is to provide something that supports the basic cases, and can be built on top of. https://discourse.llvm.org/t/rfc-a-binary-serialization-format-for-mlir/63518 Differential Revision: https://reviews.llvm.org/D131747