metagraph-dev / pymlir Goto Github PK
View Code? Open in Web Editor NEWThis project forked from spcl/pymlir
Python interface for MLIR - the Multi-Level Intermediate Representation
License: BSD 3-Clause "New" or "Revised" License
This project forked from spcl/pymlir
Python interface for MLIR - the Multi-Level Intermediate Representation
License: BSD 3-Clause "New" or "Revised" License
We currently lose the visibility attribute of "private" when round tripping MLIR input text through PyMLIR in this example:
>>> import mlir
>>> input_string = "func private @resize_pointers(!llvm.ptr<i8>, index, index) -> ()"
>>> mlir.parse_string(input_string).body[0].dump()
'func @resize_pointers(!llvm.ptr< i8 >, index, index) {\n}'
>>>
import mlir
mlir_text = r"""
func @bad_func() -> tensor<8xf32> {
%0 = constant dense<0.0> : tensor<8xf32> : tensor<8xf32>
return %0 : tensor<8xf32>
}
"""
print(mlir_text)
mlir.parse_string(mlir_text)
This should not parse. It does parse.
Ideally, %0 = constant dense<0.0> : tensor<8xf32> : tensor<8xf32>
would cause an exception to be raised.
Proximal cause:
dense_elements_attribute
. It requires a colon+type.dense_elements_attribute
is a sub-rule of elements_attribute
.elements_attribute
is a sub-rule of standard_attribute
.standard_attribute
is a sub-rule of attribute_value
.attribute_value
is used in the constant
op of the standard dialect, which additionally requires a type to be written (which means 2 type declarations in total, which causes the bug).Perhaps having this parse is a non-issue since one could argue that it might be syntactically valid (which I'm not sure I agree with) but is semantically invalid.
Here's an algorithm to generate tons of tests:
This will require an intractable amount of work, so it might not be motivated until MLIR is more stable, but it might be motivated in the future as I suspect the rules in mlir.lark are not as robust or correct as we need it to be.
This might have helped us discover #7 earlier. I suspect that there are similar problems with how standard_attribute
is currently defined (either with how it's defined or with how it's used in the dialects currently).
The MLIR docs provide rules for their syntax (e.g. here), and as far as I can tell by my cursory look, these rules describe a context-free language, so using the CFG approach taken so far via lark should in theory work. Perhaps just going down the syntax rules as listed in the MLIR docs could work as a better first step to make sure we have sufficient test coverage of things that should be accepted before we start testing things that should be not accepted.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.