You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: mlir/docs/Bindings/Python.md
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1187,3 +1187,43 @@ or nanobind and
1187
1187
utilities to connect to the rest of Python API. The bindings can be located in a
1188
1188
separate module or in the same module as attributes and types, and
1189
1189
loaded along with the dialect.
1190
+
1191
+
## Free-threading (No-GIL) support
1192
+
1193
+
Free-threading or no-GIL support refers to CPython interpreter (>=3.13) with Global Interpreter Lock made optional. For details on the topic, please check [PEP-703](https://peps.python.org/pep-0703/) and the this [link](https://py-free-threading.github.io/).
1194
+
1195
+
MLIR Python PyBind11 bindings are made free-threading compatible with exceptions (discussed below) in the following sense: it is safe to work in multiple threads with **independent** contexts/modules. Below we show an example code of safe usage:
1196
+
1197
+
```python
1198
+
# python3.13t example.py
1199
+
import concurrent.futures
1200
+
1201
+
import mlir.dialects.arith as arith
1202
+
from mlir.ir import Context, Location, Module, IntegerType, InsertionPoint
"test_execution_engine__testNanoTime_multi_threaded", # testNanoTime can't run in multiple threads, even with GIL
461
467
"test_execution_engine__testSharedLibLoad_multi_threaded", # testSharedLibLoad can't run in multiple threads, even with GIL
462
468
"test_dialects_arith_dialect__testArithValue_multi_threaded", # RuntimeError: Value caster is already registered: <class 'dialects/arith_dialect.testArithValue.<locals>.ArithValue'>, even with GIL
463
469
"test_ir_dialects__testAppendPrefixSearchPath_multi_threaded", # PyGlobals::setDialectSearchPrefixes is not thread-safe, even with GIL. Strange usage of static PyGlobals vs python exposed _cext.globals
464
470
"test_ir_value__testValueCasters_multi_threaded_multi_threaded", # RuntimeError: Value caster is already registered: <function testValueCasters.<locals>.dont_cast_int, even with GIL
471
+
"test_ir_operation_testKnownOpView_multi_threaded_multi_threaded", # uses register_operation method in the test
472
+
"test_dialects_transform_structured_ext__testMatchInterfaceEnumReplaceAttributeBuilder_multi_threaded", # uses register_attribute_builder method in the test
465
473
]
466
474
467
475
468
-
tests_to_xfail= [
476
+
TESTS_TO_XFAIL= [
469
477
# execution_engine tests, ctypes related data-races, may be false-positive as libffi was not instrumented with TSAN
"test_pass_manager__testPrintIrAfterAll_multi_threaded", # IRPrinterInstrumentation::runAfterPass is not thread-safe
487
495
"test_pass_manager__testPrintIrBeforeAndAfterAll_multi_threaded", # IRPrinterInstrumentation::runBeforePass is not thread-safe
488
496
"test_pass_manager__testPrintIrLargeLimitElements_multi_threaded", # IRPrinterInstrumentation::runAfterPass is not thread-safe
489
497
"test_pass_manager__testPrintIrTree_multi_threaded", # IRPrinterInstrumentation::runAfterPass is not thread-safe
490
498
"test_pass_manager__testRunPipeline_multi_threaded", # PrintOpStatsPass::printSummary is not thread-safe
491
-
492
499
# dialects tests
493
500
"test_dialects_memref__testSubViewOpInferReturnTypeExtensiveSlicing_multi_threaded", # Related to ctypes data races
494
501
"test_dialects_transform_interpreter__include_multi_threaded", # mlir::transform::PrintOp::apply(mlir::transform::TransformRewriter...) is not thread-safe
495
502
"test_dialects_transform_interpreter__print_other_multi_threaded", # Fatal Python error: Aborted or mlir::transform::PrintOp::apply(mlir::transform::TransformRewriter...) is not thread-safe
496
503
"test_dialects_transform_interpreter__print_self_multi_threaded", # mlir::transform::PrintOp::apply(mlir::transform::TransformRewriter...) is not thread-safe
497
504
"test_dialects_transform_interpreter__transform_options_multi_threaded", # mlir::transform::PrintOp::apply(mlir::transform::TransformRewriter...) is not thread-safe
498
505
"test_dialects_gpu_module-to-binary-rocdl__testGPUToASMBin_multi_threaded", # Due to global llvm-project/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp::GCNTrackers variable mutation
499
-
500
506
# integration tests
501
507
"test_integration_dialects_linalg_opsrun__test_elemwise_builtin_multi_threaded", # Related to ctypes data races
502
508
"test_integration_dialects_linalg_opsrun__test_elemwise_generic_multi_threaded", # Related to ctypes data races
503
-
504
509
# IR tests
505
510
"test_ir_diagnostic_handler__testDiagnosticCallbackException_multi_threaded", # mlirEmitError is not thread-safe
506
511
"test_ir_module__testParseSuccess_multi_threaded", # mlirOperationDump is not thread-safe
0 commit comments