summaryrefslogtreecommitdiff
path: root/mlir/test/python
diff options
context:
space:
mode:
authorNikhil Kalra <nkalra@apple.com>2025-02-12 14:02:41 -0800
committerGitHub <noreply@github.com>2025-02-12 14:02:41 -0800
commit65ed4fa57e6293f8e059a368ac52e2a57b1f78e4 (patch)
tree17a02320e8a2c39799c6d84f3e749c945b957926 /mlir/test/python
parentfa71238da800f3a818ec0e0649462389dc577890 (diff)
[mlir] Python: Parse ModuleOp from file path (#126572)
For extremely large models, it may be inefficient to load the model into memory in Python prior to passing it to the MLIR C APIs for deserialization. This change adds an API to parse a ModuleOp directly from a file path. Re-lands [4e14b8a](https://github.com/llvm/llvm-project/commit/4e14b8afb44af58ab7073bb8c0b52875599b0ae1).
Diffstat (limited to 'mlir/test/python')
-rw-r--r--mlir/test/python/ir/module.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/mlir/test/python/ir/module.py b/mlir/test/python/ir/module.py
index ecafcb46af21..6065e59fd6ed 100644
--- a/mlir/test/python/ir/module.py
+++ b/mlir/test/python/ir/module.py
@@ -1,6 +1,7 @@
# RUN: %PYTHON %s | FileCheck %s
import gc
+from tempfile import NamedTemporaryFile
from mlir.ir import *
@@ -27,6 +28,24 @@ def testParseSuccess():
print(str(module))
+# Verify successful parse from file.
+# CHECK-LABEL: TEST: testParseFromFileSuccess
+# CHECK: module @successfulParse
+@run
+def testParseFromFileSuccess():
+ ctx = Context()
+ with NamedTemporaryFile(mode="w") as tmp_file:
+ tmp_file.write(r"""module @successfulParse {}""")
+ tmp_file.flush()
+ module = Module.parseFile(tmp_file.name, ctx)
+ assert module.context is ctx
+ print("CLEAR CONTEXT")
+ ctx = None # Ensure that module captures the context.
+ gc.collect()
+ module.operation.verify()
+ print(str(module))
+
+
# Verify parse error.
# CHECK-LABEL: TEST: testParseError
# CHECK: testParseError: <